package com.lib.common.dialog_fragment;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentActivity;

import com.lib.common.R;
import com.google.android.material.textfield.TextInputEditText;

@SuppressLint("ValidFragment")
public class ModifyPwdDialogFragment extends BaseDialogFragment implements View.OnClickListener {
	
	private TextInputEditText mOldPwd;
	private TextInputEditText mNewPwd;
	private View mBtn;
	
	public ModifyPwdDialogFragment() {
	
	}
	
	@Override
	@SuppressLint("InflateParams")
	public void onCreate(@Nullable Bundle savedInstanceState) {
		
		super.onCreate(savedInstanceState);
		mView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_modify_pwd, null);
		mOldPwd = mView.findViewById(R.id.oldPwd);
		mNewPwd = mView.findViewById(R.id.newPwd);
		
		mBtn = mView.findViewById(R.id.btn_modify_pwd);
		mBtn.setOnClickListener(this);
	}
	
	@Override
	public void onClick(View v) {
		
		Editable mOldPwdText = mOldPwd.getText();
		String oldPwdStr;
		final FragmentActivity activity = getActivity();
		if (mOldPwdText == null || TextUtils.isEmpty(oldPwdStr = mOldPwdText.toString())) {
			Toast.makeText(activity, "请检查旧密码", Toast.LENGTH_SHORT).show();
			return;
		}
		Editable pwd = mNewPwd.getText();
		String pwdStr;
		if (pwd == null || TextUtils.isEmpty(pwdStr = pwd.toString()) || !pwdStr.matches("[a-zA-Z0-9_]{6,16}")) {
			Toast.makeText(activity, getString(R.string.no_standard_pwd), Toast.LENGTH_SHORT).show();
			return;
		}
		mBtn.setEnabled(false);
	}
}